package com.jdjc.auth.domin.service.impl;


import cn.dev33.satoken.secure.SaSecureUtil;
import com.jdjc.auth.common.enums.AuthUserStatusEnum;
import com.jdjc.auth.common.enums.IsDeletedFlagEnum;
import com.jdjc.auth.domin.convert.AuthRoleDominConverter;
import com.jdjc.auth.domin.convert.AuthUserDominConverter;
import com.jdjc.auth.domin.entity.AuthRoleBO;
import com.jdjc.auth.domin.service.AuthRoleDominService;
import com.jdjc.auth.infra.basic.entity.AuthRole;
import com.jdjc.auth.infra.basic.entity.AuthUser;
import com.jdjc.auth.infra.basic.service.AuthRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("AuthRoleDominService")
@Slf4j
public class AuthRoleDominServiceImpl implements AuthRoleDominService {
    @Resource
    private AuthRoleService authRoleService;

    /**
     * 新增角色
     * @param authRoleBO
     * @return
     */
    @Override
    public Boolean add(AuthRoleBO authRoleBO) {
        if (log.isInfoEnabled()) {
            log.info(" AuthRoleDominServiceImpl：add:BO:{}", authRoleBO);
        }
        AuthRole authRole = AuthRoleDominConverter.INSTANCE.convertBOToEntity(authRoleBO);

        authRole.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        int count = authRoleService.insert(authRole);
        return count > 0;
    }

    /**
     * 修改角色
     * @param authRoleBO
     * @return
     */
    @Override
    public Boolean update(AuthRoleBO authRoleBO) {
        if (log.isInfoEnabled()) {
            log.info(" AuthRoleDominServiceImpl：update:BO:{}", authRoleBO);
        }
        AuthRole authRole = AuthRoleDominConverter.INSTANCE.convertBOToEntity(authRoleBO);
        int count = authRoleService.update(authRole);
        return count > 0;
    }

    /**
     * 逻辑删除角色
     * @param authRoleBO
     * @return
     */
    @Override
    public Boolean delete(AuthRoleBO authRoleBO) {
        if (log.isInfoEnabled()) {
            log.info(" AuthRoleDominServiceImpl：delete:BO:{}", authRoleBO);
        }
        AuthRole authRole = new AuthRole();
        authRole.setId(authRoleBO.getId());
        authRole.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
        int count = authRoleService.update(authRole);
        return count > 0;
    }
}
